/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package scms;

import java.util.LinkedList;
import java.io.*;

/**
 * Holds data relating to a single inventory item
 * @author pumped
 */
public class InventoryItem implements Serializable {

	private int id;
	private String name;
	private String description;
	private int quality;
	private int quantity;
	private LinkedList<Part> parts = new LinkedList<Part>();

	/**
	 * prints brief inventory item details out
	 */
	public void print() {
		System.out.println(id + " " + name + " - " + description);
	}

	/**
	 * prints full details of inventory item out
	 */
	public void printFull() {
		System.out.println("ID: " + getID());
		System.out.println("Name: " + getName());
		System.out.println("Description: " + getDescription());
		System.out.println("Quality: " + getQuality());
		System.out.println("Quantity: " + getQuantity());
	}

	/**
	 * adds a part to this item
	 * @param part part to be added
	 */
	public void addPart(InventoryItem item, int amount) {
		Part part = new Part();
		part.item = item;
		part.amount = amount;
		parts.add(part);
	}

	/**
	 * edit function to edit item details
	 */
	public void modify() {
		printFull();
		if (StreamIO.readString("Change name (y)es [n]o: ").equals("y")) {
			setName(StreamIO.readString("New name: "));
		}
		if (StreamIO.readString("Change description (y)es [n]o: ").equals("y")) {
			setDescription(StreamIO.readString("New description: "));
		}
		if (StreamIO.readString("Change Quality (y)es [n]o: ").equals("y")) {
			setQuality(StreamIO.readInt("New Quality: "));
		}
		if (StreamIO.readString("Change Quantity (y)es [n]o: ").equals("y")) {
			setQuality(StreamIO.readInt("New Quantity: "));
		}

	}

	/**
	 * prints out items parts
	 */
	public void printParts() {
		for (Part p : parts) {
			System.out.println(" - " + p.item.getName());
			p.item.printParts();
		}

	}

	/**
	 * returns items name
	 * @return name
	 */
	public String getName() {
		return name;
	}

	/**
	 * sets items name
	 * @param name
	 */
	public void setName(String name) {
		this.name = name;
	}

	/**
	 * returns items description
	 * @return description
	 */
	public String getDescription() {
		return description;
	}

	/**
	 * sets items description
	 * @param description
	 */
	public void setDescription(String description) {
		this.description = description;
	}

	/**
	 * returns items id
	 * @return id
	 */
	public int getID() {
		return id;
	}

	/**
	 * sets items id
	 * @param id
	 */
	public void setID(int id) {
		this.id = id;
	}

	/**
	 * returns itesm quality
	 * @return quality
	 */
	public int getQuality() {
		return quality;
	}

	/**
	 * sets items quality
	 * @param quality
	 */
	public void setQuality(int quality) {
		this.quality = quality;
	}

	/**
	 * returns items quality
	 * @return quality
	 */
	public int getQuantity() {
		return quantity;
	}

	/**
	 * sets quantity of item in stock
	 * @param quantity
	 */
	public void setQuantity(int quantity) {
		this.quantity = quantity;
	}

	/**
	 * returns Linked list of parts
	 * @return parts
	 */
	public LinkedList<Part> getParts() {
		return parts;
	}

	/**
	 * removes parts from item
	 */
	public void deleteParts() {
		parts = new LinkedList<Part>();
	}
}
